const {
  houseDesc_mock
} = require("../../../mock/house.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //是否收藏
    likeFlag: true,
    //房源id
    houseId: '',
    //房源详情
    houseDesc: '',
    //轮播图
    autoplay: true, //是否自动切换
    interval: 2000, //自动切换时间间隔【默认5000】
    indicatorDots: true, //是否显示面板指示点【默认false	】
    indicatorColor: "#ffffff", //指示点颜色【默认rgba(0, 0, 0, .3)】
    indicatorActiveColor: "#20d86e", //当前选中的指示点颜色【默认#000000】
    vertical: false, //滑动方向是否为纵向【默认false】
    duration: 500, //滑动动画时长【默认500】
    circular: false, //是否采用衔接滑动【默认false】
    //预约
    appointmentShow: false,
    //当天年月日
    curentyear: '',
    curentMonth: '',
    curentDay: '',
    //选中的日期
    choiceDay: '',
    dayNumbers: [0, 1, 2, 3, 4],
    //选中的时间
    choiceTime: '',
    timeNumbers: ["9:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00", ],
    //预约成功
    appointmentOkShow: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({ //模拟数据
      houseId: options.houseId,
      houseDesc: houseDesc_mock
    })
    console.log(options.houseId)
  },
  /**
   * 返回上个页面
   */
  toLastPage() {
    wx.navigateBack();
    console.log("返回上个页面")
  },
  /**
   * 跳转到小区详情页面
   */
  onPlotPage(e) {
    wx.navigateTo({
      url: '/pages/house/plot/plot?housePlotId=' + e.currentTarget.dataset.houseplotid,
    })
  },
  /**
   *收藏事件 
   */
  onLike() {
    if (this.data.likeFlag) {
      this.setData({
        likeFlag: false
      })
      wx.showToast({
        title: '取消收藏',
        icon: 'success',
        duration: 2000
      })

    } else {
      this.setData({
        likeFlag: true
      })
      wx.showToast({
        title: '收藏成功',
        icon: 'success',
        duration: 2000
      })

    }

  },
  /**
   * 复制电话
   */
  onPhone() {
    //const contentToCopy = this.data.houseDesc.houseBroker.houseBrokerPhone;
    const contentToCopy = "15083344188";
    wx.setClipboardData({
      data: contentToCopy,
      success: function (res) {
        wx.showToast({
          title: '复制电话成功',
        });
      },
      fail: function (res) {
        wx.showToast({
          title: '复制失败',
          icon: 'none',
        });
      }
    });
  },
  /**
   * 复制微信
   */
  onWX() {
    //const contentToCopy = this.data.houseDesc.houseBroker.houseBrokerWX;
    const contentToCopy = "wx_text";
    wx.setClipboardData({
      data: contentToCopy,
      success: function (res) {
        wx.showToast({
          title: '复制微信成功',
        });
      },
      fail: function (res) {
        wx.showToast({
          title: '复制失败',
          icon: 'none',
        });
      }
    });
  },
  /**
   * 预约弹出框
   */
  //1.打开
  onOpen() {
    //获取当天的月-日
    const now = new Date();
    const month = String(now.getMonth() + 1).padStart(2, '0');
    const day = String(now.getDate()).padStart(2, '0');
    const year = now.getFullYear();
     //获取年
     const formattedYear = Number(`${year}`);
    //获取月
    const formattedMonth = Number(`${month}`);
    //获取日
    const formattedDay = Number(`${day}`);
    console.log(formattedYear);
    //console.log(formattedMonth);
    //console.log(formattedDay+1);
    this.setData({
      appointmentShow: true,
      curentYear: formattedYear,
      curentMonth: formattedMonth,
      curentDay: formattedDay
    })
  },
  //2.关闭
  onClose() {
    this.setData({
      appointmentShow: false
    })
  },
  //日期切换
  onDayChange(event) {
    console.log(event.detail.title) //标签的title属性
    this.setData({
      choiceDay: event.detail.title
    })
  },
  //时间切换事件
  onTimeChange(e) {
    console.log(e.currentTarget.dataset.time) //标签的title属性
    this.setData({
      choiceTime: e.currentTarget.dataset.time
    })
  },
  //提交预约
  onAppointmentSubmit() {
    if (this.data.choiceDay != '' && this.data.choiceTime != '') {
      console.log(this.data.curentYear + '-'+this.data.choiceDay + ' ' + this.data.choiceTime) //标签的title属性
      this.setData({
        appointmentShow: false,
        appointmentOkShow:true
      })
    } else {
      wx.showToast({
        title: '请选择日期和时间',
        icon: 'success',
        duration: 2000
      })
    }
  },
  /**
   * 预约成功弹出框
   */
  //1.打开
  onOkOpen() {
    this.setData({
      appointmentOkShow:true
    })
  },
  //2.关闭
  onOkClose() {
    this.setData({
      appointmentOkShow: false
    })
  },
  //3.查看约看详情
  onMyAppointmentPage(){
    wx.navigateTo({
      url: '/pages/user/appointment/appointment',
    })
  }


})